package com.github.coolcool.sloth.lianjiadb.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import com.github.coolcool.sloth.lianjiadb.mapper.AreaMapper;
import com.github.coolcool.sloth.lianjiadb.model.Area;
import com.github.coolcool.sloth.lianjiadb.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.coolcool.sloth.lianjiadb.common.Page;
import javax.annotation.Generated;


@Generated(
	value = {
		"https://github.com/coolcooldee/sloth",
		"Sloth version:1.0"
	},
	comments = "This class is generated by Sloth"
)
@Service
public  class AreaServiceImpl implements AreaService{

	Logger logger = LoggerFactory.getLogger(AreaService.class);

	@Autowired
	private AreaMapper areaMapper;

	public Integer save(Area area){
		return areaMapper.insert(area);
	}

	@Override
	public Area getById(Object id){
		return areaMapper.getByPrimaryKey(id);
	}
	@Override
	public void deleteById(Object id){
		areaMapper.deleteByPrimaryKey(id);
	}
	@Override
	public void update(Area area){
		areaMapper.updateByPrimaryKey(area);
	}

	@Override
	public Integer count(){
	    return areaMapper.count();
	}

	@Override
	public List<Area> listAll(){
		return areaMapper.listAll();
	}

	@Override
	public List<Area> listOneLevelChilden(int id) {
		return areaMapper.listOneLevelChilden(id);
	}

	@Override
	public List<Area> listTwoLevelChilden(int id) {
		return areaMapper.listTwoLevelChilden(id);
	}

	@Override
	public Page<Area> page(int pageNo, int pageSize) {
		Page<Area> page = new Page<>();
        int start = (pageNo-1)*pageSize;
        page.setPageSize(pageSize);
        page.setStart(start);
        page.setResult(areaMapper.page(start,pageSize));
        page.setTotalCount(areaMapper.count());
        return page;
	}

	@Override
	public Integer increment(){
		return areaMapper.increment();
	}
	
}